package com.kfm.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/testForward")
public class TestForwardServlet extends HttpServlet {

    // 请求转发之后的请求方式跟之前的保持一致
    // 重定向之后的请求方式都是get请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("testForward get");
//        req.getRequestDispatcher("/forward").forward(req, resp);
        resp.sendRedirect("/forward");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("testForward post");
//        req.getRequestDispatcher("/forward").forward(req, resp);
        resp.sendRedirect("/forward");
    }
}
